package com.cp.yn.activity

import android.content.Intent
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.viewholder.QuickViewHolder
import com.common.base.base.BaseActivity
import com.common.base.base.BaseRecyclerViewAdapter
import com.common.base.tools.arouter.endRouter
import com.cp.yn.databinding.ActivityNationalFlagBinding
import com.cp.yn.manager.RouterManager
import com.didi.drouter.annotation.Router
import com.google.gson.reflect.TypeToken
import com.common.base.tools.extend.getResourceMipmap
import com.common.base.tools.utils.JsonUtils
import com.cp.yn.R
import com.cp.yn.bean.NationalBean

@Router(path = RouterManager.Path.APP_NationalFlag)
class NationalFlagActivity : BaseActivity<ActivityNationalFlagBinding>() {
    var adapter: BaseRecyclerViewAdapter<NationalBean> =
        BaseRecyclerViewAdapter(R.layout.adapter_national_flag)

    override fun viewBinding(): ActivityNationalFlagBinding {
        return ActivityNationalFlagBinding.inflate(layoutInflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        val nationalFlag = JsonUtils.readAssetsJson("national.json")
//        val nationalBean = JsonUtils.fromJson<MutableList<NationalBean>>(
//            nationalFlag,
//            object : TypeToken<List<NationalBean>>() {}.type
//        )
        adapter.submitList(listOf(NationalBean(),NationalBean()))

        adapter.setOnBindViewHolder(object :
            BaseRecyclerViewAdapter.OnBindViewHolder<NationalBean> {
            override fun onResult(helper: QuickViewHolder?, position: Int, info: NationalBean) {
//                helper?.setImageResource(
//                    R.id.national_icon,
//                    getResourceMipmap(info.icon)
//                )
            }
        })

        viewBinding.mRecyclerView.layoutManager = LinearLayoutManager(this)
        viewBinding.mRecyclerView.adapter = adapter
//        adapter.submitList(nationalBean)
        adapter.setOnItemClickListener { adapter, view, position ->
            endRouter(
                Intent().putExtra(
                    RouterManager.Key.APP_NationalFlag_Result,
                    adapter.getItem(position)
                )
            )
        }
    }


}